package logic

import (
	"context"
	"go-exp/zero/rpc/user/pb/user"

	"go-exp/zero/api/internal/svc"
	"go-exp/zero/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoLogic {
	return &GetUserInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetUserInfoLogic) GetUserInfo(req *types.GetUserInfoRequest) (resp *types.UserInfo, err error) {
	// todo: add your logic here and delete this line
	getUser, err := l.svcCtx.UserRpc.GetUser(l.ctx, &user.GetUserRequest{Id: req.ID})
	if err != nil {
		return nil, err
	}
	resp = &types.UserInfo{
		ID:        getUser.Id,
		Username:  getUser.Username,
		CreatedAt: getUser.CreatedAt,
	}
	return
}
